#define BLINKER_BLE //点灯模式：蓝牙
#define ONE_WIRE_BUS 4// ds18b20数据线已插入Arduino上的端口4
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Blinker.h>//点灯：头文件
#include <stdio.h>
 OneWire oneWire(ONE_WIRE_BUS);  // 设置oneWire实例以与任何oneWire设备通信
 DallasTemperature sensors(&oneWire);// 通过我们的oneWire参考达拉斯温度

 BlinkerNumber WENA("wena");//对应点灯数据wen1
 BlinkerNumber WENB("wenb");//对应点灯数据wen2
 BlinkerNumber WENC("wenc");//对应点灯数据wen3 
 BlinkerNumber WEND("wend");//对应点灯数据wen4
 BlinkerNumber WENE("wene");//对应点灯数据wen5 
 BlinkerNumber WENF("wenf");//对应点灯数据wen6
 BlinkerNumber WEN1("wen1");//对应点灯数据wen7
 BlinkerNumber WENH("wenh");//对应点灯数据wen8
 BlinkerNumber WENHIGE("wenhige");//对应点灯数据wenhige
 
 float tempC1,tempC2,tempC3,tempC4,tempC5,tempC6,tempC7,tempC8,wenhige_read,wenlow_read;
 int min, max;

  // 8个ds18b20的地址
 uint8_t sensor1[8] = { 0x28, 0xD7, 0x74, 0xEB, 0x19, 0x13, 0x01, 0xD3 };
 uint8_t sensor2[8] = { 0x28, 0xBC, 0x02, 0xD7, 0x19, 0x13, 0x01, 0x43 };
 uint8_t sensor3[8] = { 0x28, 0x49, 0xCE, 0xD2, 0x19, 0x13, 0x01, 0x58 };
 uint8_t sensor4[8] = { 0x28, 0x02, 0x92, 0xE1, 0x19, 0x13, 0x01, 0xA1 };
 uint8_t sensor5[8] = { 0x28, 0xB5, 0xA2, 0xD4, 0x19, 0x13, 0x01, 0x6E };
 uint8_t sensor6[8] = { 0x28, 0xD7, 0x98, 0xE4, 0x19, 0x13, 0x01, 0xB2 };
 uint8_t sensor7[8] = { 0x28, 0x34, 0x15, 0xE0, 0x19, 0x13, 0x01, 0xEB };
 uint8_t sensor8[8] = { 0x28, 0x65, 0xDA, 0xD0, 0x19, 0x13, 0x01, 0xF7 };
// N个ds18b20的地址（如没达到则留空，最高支持8个ds18b20）

 void setup(void)
 {
   Serial.begin(9600);
   sensors.begin();
   Blinker.begin();// 默认设置: 数字IO 2(RX) 3(TX), 波特率 9600 bps
 }

 
 void loop(void)//循环输出温度
 {
  Blinker.run();
   sensors.requestTemperatures();
   
   Serial.print("Sensor 1: ");
   tempC1 = sensors.getTempC(sensor1);
   WENA.print(tempC1);
   Serial.print(tempC1);
   Serial.print("°C  |  ");
   
   Serial.print("Sensor 2: ");
   tempC2 = sensors.getTempC(sensor2);
   WENB.print(tempC2);
   Serial.print(tempC2);
   Serial.print("°C  |  ");
   
   Serial.print("Sensor 3: ");
   tempC3 = sensors.getTempC(sensor3);
   Serial.print(tempC3);
   Serial.print("°C  |  ");
   WENC.print(tempC3);
   
   Serial.print("Sensor 4: ");
   tempC4 = sensors.getTempC(sensor4);
   WEND.print(tempC4);
   Serial.print(tempC4);
   Serial.print("°C  |  ");
   Blinker.run();
   
   Serial.print("Sensor 5: ");
   tempC5 = sensors.getTempC(sensor5);
   WENE.print(tempC5);
   Serial.print(tempC5);
   Serial.print("°C  |  ");

   Serial.print("Sensor 6: ");
   tempC6 = sensors.getTempC(sensor6);
   WENF.print(tempC6);
   Serial.print(tempC6);
   Serial.print("°C  |  ");

   Serial.print("Sensor 7: ");
   tempC7 = sensors.getTempC(sensor7);
   WEN1.print(tempC7);
   Serial.print(tempC7);
   Serial.print("°C  |  ");

   Serial.print("Sensor 8: ");
   tempC8 = sensors.getTempC(sensor8);
   WENH.print(tempC8);
   Serial.print(tempC8);
   Serial.print("°C  |  ");

float temperatures[8] = {tempC1, tempC2, tempC3, tempC4, tempC5, tempC6, tempC7, tempC8};
float maxTemp = temperatures[0];
for(int i = 1; i < 8; i++) {
  if(temperatures[i] > maxTemp) {
    maxTemp = temperatures[i];
  }
}
wenhige_read = maxTemp;
WENHIGE.print(wenhige_read);
Serial.println(wenhige_read);

   Serial.println();
  
   delay(1000);
 }
